package com.ssy.lingxi.marketing.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 *  平台活动外部状态
 * @author ds
 * @date 2021/6/18
 * @version 2.0.0
 * @see PlatformActivityOuterStatusEnum
 */
public enum PlatformActivityOuterStatusEnum {

    ALL(0, "所有状态"),
    TO_BE_SUBMIT(1, "待提交"),
    TO_BE_SIGN_UP(2, "待报名"),
    TO_BE_EXAMINE_SIGN_UP(3, "待审核报名"),
    // 4与5，为会员外部状态对应[非平台活动外部状态]4：报名审核通过，5：报名审核不通过
    TO_BE_ONLINE(6, "待上线活动"),
    ONGOING(7, "活动进行"),
    STOP(8, "活动终止"),
    END(9, "活动结束"),
    CANCEL(10, "活动取消"),
    ;

    private final Integer code;
    private final String message;

    PlatformActivityOuterStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    public static String getMessage(Integer code) {
        PlatformActivityOuterStatusEnum statusEnum = Arrays.stream(PlatformActivityOuterStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return statusEnum == null ? "" : statusEnum.getMessage();
    }

    /**
     * 是否可取消（2,3,6,8）
     */
    public static boolean canCancel(Integer code) {
        List<PlatformActivityOuterStatusEnum> collect = Stream.of(TO_BE_SIGN_UP, TO_BE_EXAMINE_SIGN_UP, TO_BE_ONLINE, STOP).collect(Collectors.toList());
        return collect.stream().anyMatch(o -> o.getCode().equals(code));
    }

    /**
     * 活动取消和活动结束，这两个状态可以重新选择商品
     */
    public static List<Integer> getAllowRejoinActivityStatusList() {
        return Stream.of(END, CANCEL).map(PlatformActivityOuterStatusEnum::getCode).collect(Collectors.toList());
    }

    /**
     * 商户查询活动执行，外部状态限定（待上线活动、活动进行、活动终止、活动结束、活动取消状态的平台活动）
     */
    public static List<Integer> getMerchantExecuteStatusList() {
        return Stream.of(TO_BE_ONLINE,ONGOING,STOP,END, CANCEL).map(PlatformActivityOuterStatusEnum::getCode).collect(Collectors.toList());
    }

}
